package com.dinzeer.sjapadder.register;

import cn.mmf.slashblade_addon.specialattacks.WaterDrive;
import com.dinzeer.legendreliclib.lib.compat.slashblade.Drives;
import com.dinzeer.sjapadder.Config;
import com.dinzeer.sjapadder.Sjap_adder;
import com.dinzeer.sjapadder.sa.*;
import mods.flammpfeil.slashblade.SlashBlade;
import mods.flammpfeil.slashblade.ability.StunManager;
import mods.flammpfeil.slashblade.event.client.UserPoseOverrider;
import mods.flammpfeil.slashblade.event.handler.FallHandler;
import mods.flammpfeil.slashblade.init.DefaultResources;
import mods.flammpfeil.slashblade.registry.combo.ComboState;
import mods.flammpfeil.slashblade.slasharts.WaveEdge;
import mods.flammpfeil.slashblade.util.AttackManager;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.RegistryObject;

import static com.dinzeer.sjapadder.Sjap_adder.MODID;

public class SjaComboRegistry {
    public static final DeferredRegister<ComboState> COMBO_STATES =
            DeferredRegister.create(ComboState.REGISTRY_KEY,MODID);
    public static final RegistryObject<ComboState> ALL_REUSE = COMBO_STATES.register
            (
                    "all_reuse",
                    ComboState.Builder.newInstance().startAndEnd(459, 488).priority(50)
                            .motionLoc(DefaultResources.ExMotionLocation).next(entity -> SlashBlade.prefix("none"))
                            .nextOfTimeout(entity -> SlashBlade.prefix("none"))
                            .addTickAction(ComboState.TimeLineTickAction.getBuilder().put(0, AttackManager::playQuickSheathSoundAction).build())
                            .releaseAction(ComboState::releaseActionQuickCharge)::build
            );

    public static final RegistryObject<ComboState> EXPLOSIVE_DAWN = COMBO_STATES.register("explosive_dawn",
            ComboState.Builder.newInstance().startAndEnd(400, 459).priority(50)
                    .motionLoc(DefaultResources.ExMotionLocation)
                    .next(ComboState.TimeoutNext.buildFromFrame(15, entity -> SlashBlade.prefix("none")))
                    .nextOfTimeout(entity -> Sjap_adder.prefix("all_reuse"))
                    .addTickAction(ComboState.TimeLineTickAction.getBuilder()
                            .put(2, ExplosiveDawn::doPreExplosiveDawn)
                            .put(8, ExplosiveDawn::doExplosiveDawn)
                            .build())
                    .addHitEffect(StunManager::setStun)
                    ::build);

    public static final RegistryObject<ComboState> Dance = COMBO_STATES.register("fire_dance",
            ComboState.Builder.newInstance().startAndEnd(400, 459).priority(50)
                    .motionLoc(DefaultResources.ExMotionLocation)
                    .next(ComboState.TimeoutNext.buildFromFrame(15, entity -> SlashBlade.prefix("none")))
                    .nextOfTimeout(entity -> Sjap_adder.prefix("all_reuse"))
                    .addTickAction(ComboState.TimeLineTickAction.getBuilder()
                            .put(2, (entityIn) -> AttackManager.doSlash(entityIn, -30F, Vec3.ZERO, false, false, Config.fireDanceComboRatio))
                            .put(3, FireDance::doBurningDance)
                            .build())
                    .addHitEffect(StunManager::setStun)
                    ::build);
    public static final RegistryObject<ComboState> BurningDances = COMBO_STATES.register("burning_dance",
            ComboState.Builder.newInstance().startAndEnd(400, 459).priority(50)
                    .motionLoc(DefaultResources.ExMotionLocation)
                    .next(ComboState.TimeoutNext.buildFromFrame(15, entity -> SlashBlade.prefix("none")))
                    .nextOfTimeout(entity -> Sjap_adder.prefix("all_reuse"))
                    .addTickAction(ComboState.TimeLineTickAction.getBuilder()
                            .put(2, (entityIn) -> AttackManager.doSlash(entityIn, -30F, Vec3.ZERO, false, false, Config.burningDanceComboRatio))
                            .put(3, BurningDance::doBurningDance)
                            .build())
                    .addHitEffect(StunManager::setStun)
                    ::build);
    public static final RegistryObject<ComboState> ColdDrive = COMBO_STATES.register("cold_drive",
            ComboState.Builder.newInstance().startAndEnd(400, 459).priority(50)
                    .motionLoc(DefaultResources.ExMotionLocation)
                    .next(ComboState.TimeoutNext.buildFromFrame(15, entity -> SlashBlade.prefix("none")))
                    .nextOfTimeout(entity -> Sjap_adder.prefix("all_reuse"))
                    .addTickAction(ComboState.TimeLineTickAction.getBuilder()
                            .put(2, (entityIn) -> AttackManager.doSlash(entityIn, -30F, Vec3.ZERO, false, false, Config.coldDriveComboRatio))
                            .put(3,(entityIn)-> Drives.spawnForwardDrive(entityIn, 5, 1, 90,40))
                            .put(4,DriveSum::doSlashForQueen)
                            .build())
                    .addHitEffect(StunManager::setStun)
                    ::build);


    public static final RegistryObject<ComboState> SAKURA_WAVE_EDGE_LEFT = COMBO_STATES.register("sakura_wave_edge_left",
            ComboState.Builder.newInstance().startAndEnd(1816, 1859).speed(6F).priority(50)
                    .next((entity) -> Sjap_adder.prefix("sakura_wave_edge_right"))
                    .nextOfTimeout(entity -> Sjap_adder.prefix("sakura_wave_edge_right"))
                    .clickAction((entityIn) -> AttackManager.doSlash(entityIn, 22.5F, Vec3.ZERO, false, false, Config.sakuraWaveEdgeLeftComboRatio))
                    .addTickAction(UserPoseOverrider::resetRot)
                    .addTickAction(ComboState.TimeLineTickAction.getBuilder()
                            .put(1,
                                    (entityIn) ->
                                            WaveEdge.doSlash(entityIn, 22.5F, 20, Vec3.ZERO, false, 3, 0.2f, 1.5f, 4))
                            .build())
                    .addHitEffect(StunManager::setStun)::build);

    public static final RegistryObject<ComboState> SAKURA_WAVE_EDGE_RIGHT = COMBO_STATES.register("sakura_wave_edge_right",
            ComboState.Builder.newInstance().startAndEnd(204, 218).speed(1.1F).priority(50)
                    .next((entity) -> SlashBlade.prefix("none"))
                    .nextOfTimeout(entity -> Sjap_adder.prefix("sakura_wave_edge_finish"))
                    .clickAction((entityIn) -> AttackManager.doSlash(entityIn, 180F - 22.5F, Vec3.ZERO, false, true, Config.sakuraWaveEdgeRightComboRatio))
                    .addTickAction(UserPoseOverrider::resetRot)
                    .addTickAction(ComboState.TimeLineTickAction.getBuilder()
                            .put(1,
                                    (entityIn) ->
                                            WaveEdge.doSlash(entityIn, -22.5F, 20, Vec3.ZERO, false, 3, 0.2f, 1.5f, 4))
                            .build())                    .addHitEffect((t, a) -> StunManager.setStun(t, 36))::build);

    public static final RegistryObject<ComboState> SAKURA_WAVE_EDGE_FINISH = COMBO_STATES.register("sakura_wave_edge_finish",
            ComboState.Builder.newInstance().startAndEnd(218, 281).priority(50).aerial()
                    .next(entity -> SlashBlade.prefix("none"))
                    .nextOfTimeout(entity -> Sjap_adder.prefix("sakura_wave_edge_finish2"))::build);
    public static final RegistryObject<ComboState> SAKURA_WAVE_EDGE_FINISH2 = COMBO_STATES.register("sakura_wave_edge_finish2",
            ComboState.Builder.newInstance().startAndEnd(281, 314).priority(80)
                    .next(entity -> SlashBlade.prefix("none")).nextOfTimeout(entity -> SlashBlade.prefix("none"))
                    .addTickAction(ComboState.TimeLineTickAction.getBuilder()
                            .put(0, AttackManager::playQuickSheathSoundAction).build())
                    .releaseAction(ComboState::releaseActionQuickCharge)::build);

    public static final RegistryObject<ComboState> terrifyingwaves = COMBO_STATES.register("terrifying_waves",
            ComboState.Builder.newInstance().startAndEnd(400, 459).priority(50)
                    .motionLoc(DefaultResources.ExMotionLocation)
                    .next(ComboState.TimeoutNext.buildFromFrame(15, entity -> SlashBlade.prefix("none")))
                    .nextOfTimeout(entity -> Sjap_adder.prefix("all_reuse"))
                    .addTickAction(ComboState.TimeLineTickAction.getBuilder()
                            .put(2, (entityIn) -> AttackManager.doSlash(entityIn, -30F, Vec3.ZERO, false, false, Config.terrifyingWavesComboRatio))
                            .put(3, (entityIn) -> WaterDrive.doSlash(entityIn,90,10,Vec3.ZERO,false,2.2,1F))
                            .put(4, (entityIn) -> WaterDrive.doSlash(entityIn,90,10,Vec3.ZERO,false,2.2,1F))
                            .put(5, (entityIn) -> WaterDrive.doSlash(entityIn,90,10,Vec3.ZERO,false,2.2,1F))
                            .put(6, (entityIn) -> WaterDrive.doSlash(entityIn,90,10,Vec3.ZERO,false,2.2,1F))
                            .put(7, (entityIn) -> WaterDrive.doSlash(entityIn,90,10,Vec3.ZERO,false,2.2,1F))
                            .put(8, (entityIn) -> WaterDrive.doSlash(entityIn,90,10,Vec3.ZERO,false,2.2,1F))
                            .put(9, (entityIn) -> WaterDrive.doSlash(entityIn,90,10,Vec3.ZERO,false,2.2,1F))
                            .build())
                    .addHitEffect(StunManager::setStun)
                    ::build);

    public static final RegistryObject<ComboState> lightinggwaves = COMBO_STATES.register("lighting_swordsex",
            ComboState.Builder.newInstance().startAndEnd(400, 459).priority(50)
                    .motionLoc(DefaultResources.ExMotionLocation)
                    .next(ComboState.TimeoutNext.buildFromFrame(15, entity -> SlashBlade.prefix("none")))
                    .nextOfTimeout(entity -> Sjap_adder.prefix("all_reuse"))
                    .addTickAction(ComboState.TimeLineTickAction.getBuilder()
                            .put(2, (entityIn) -> AttackManager.doSlash(entityIn, -30F, Vec3.ZERO, false, false, Config.lightingSwordsExComboRatio))
                            .put(3, Nightingales::slash)
                            .put(10, Nightingales::slash)
                            .build())
                    .addHitEffect(StunManager::setStun)
                    ::build);
    public static final RegistryObject<ComboState> forLife = COMBO_STATES.register("for_life",
            ComboState.Builder.newInstance().startAndEnd(400, 459).priority(50)
                    .motionLoc(DefaultResources.ExMotionLocation)
                    .next(ComboState.TimeoutNext.buildFromFrame(15, entity -> SlashBlade.prefix("none")))
                    .nextOfTimeout(entity -> Sjap_adder.prefix("all_reuse"))
                    .addTickAction(ComboState.TimeLineTickAction.getBuilder()
                            .put(2, (entityIn) -> AttackManager.doSlash(entityIn, -30F, Vec3.ZERO, false, false, Config.forLifeComboRatio))
                            .put(3, ForLife::doForLife)
                            .build())
                    .addHitEffect(StunManager::setStun)
                    ::build);
    public static final RegistryObject<ComboState> forLifeDrive = COMBO_STATES.register("for_life_dive",
            ComboState.Builder.newInstance().startAndEnd(400, 459).priority(50)
                    .motionLoc(DefaultResources.ExMotionLocation)
                    .next(ComboState.TimeoutNext.buildFromFrame(15, entity -> SlashBlade.prefix("none")))
                    .nextOfTimeout(entity -> Sjap_adder.prefix("all_reuse"))
                    .addTickAction(ComboState.TimeLineTickAction.getBuilder()
                            .put(2, (entityIn) -> AttackManager.doSlash(entityIn, -30F, Vec3.ZERO, false, false, Config.forLifeDiveComboRatio))
                            .put(3, ForLife::doForLife2)
                            .build())
                    .addHitEffect(StunManager::setStun)
                    ::build);

    public static final RegistryObject<ComboState> SuperBloodCuts =COMBO_STATES.register("super_blood_cut",
            ComboState.Builder.newInstance().startAndEnd(1923, 1928).speed(0.4F).priority(50)
                    .next(ComboState.TimeoutNext.buildFromFrame(15, entity -> SlashBlade.prefix("none")))
                    .nextOfTimeout(entity -> Sjap_adder.prefix("all_reuse"))
                    .addTickAction(ComboState.TimeLineTickAction.getBuilder()
                            .put(7,SuperBloodCut::summonJudgementCut)
                            .build())
                    .addTickAction(FallHandler::fallDecrease).addHitEffect(StunManager::setStun)::build);
    public static final RegistryObject<ComboState> illusionDrive = COMBO_STATES.register("illusion_drive",
            ComboState.Builder.newInstance().startAndEnd(400, 459).priority(50)
                    .motionLoc(DefaultResources.ExMotionLocation)
                    .next(ComboState.TimeoutNext.buildFromFrame(15, entity -> SlashBlade.prefix("none")))
                    .nextOfTimeout(entity -> Sjap_adder.prefix("all_reuse"))
                    .addTickAction(ComboState.TimeLineTickAction.getBuilder()
                            .put(2, (entityIn) -> AttackManager.doSlash(entityIn, -30F, Vec3.ZERO, false, false, Config.illusionDriveComboRatio))
                            .put(3, DriveSum::doSlash)
                            .build())
                    .addHitEffect(StunManager::setStun)
                    ::build);
    public static final RegistryObject<ComboState> RainBowDrives = COMBO_STATES.register("rainbow_drive",
            ComboState.Builder.newInstance().startAndEnd(400, 459).priority(50)
                    .motionLoc(DefaultResources.ExMotionLocation)
                    .next(ComboState.TimeoutNext.buildFromFrame(15, entity -> SlashBlade.prefix("none")))
                    .nextOfTimeout(entity -> Sjap_adder.prefix("all_reuse"))
                    .addTickAction(ComboState.TimeLineTickAction.getBuilder()
                            .put(2, (entityIn) -> AttackManager.doSlash(entityIn, -30F, Vec3.ZERO, false, false, Config.rainbowDriveComboRatio))
                            .put(3, RainBowDrive::doslash)
                            .build())
                    .addHitEffect(StunManager::setStun)
                    ::build);
    public static final RegistryObject<ComboState> WaveEdgeSupers = COMBO_STATES.register("wave_edge_super",
            ComboState.Builder.newInstance().startAndEnd(400, 459).priority(50)
                    .motionLoc(DefaultResources.ExMotionLocation)
                    .next(ComboState.TimeoutNext.buildFromFrame(15, entity -> SlashBlade.prefix("none")))
                    .nextOfTimeout(entity -> Sjap_adder.prefix("all_reuse"))
                    .addTickAction(ComboState.TimeLineTickAction.getBuilder()
                            .put(2, (entityIn) -> AttackManager.doSlash(entityIn, -30F, Vec3.ZERO, false, false, Config.waveEdgeSuperComboRatio))
                            .put(3, WaveEdgeSuper::doslash)
                            .build())
                    .addHitEffect(StunManager::setStun)
                    ::build);


    public static final RegistryObject<ComboState> DarkCuts =COMBO_STATES.register("dark_cut",
            ComboState.Builder.newInstance().startAndEnd(1923, 1928).speed(0.4F).priority(50)
                    .next(ComboState.TimeoutNext.buildFromFrame(15, entity -> SlashBlade.prefix("none")))
                    .nextOfTimeout(entity -> Sjap_adder.prefix("all_reuse"))
                    .addTickAction(ComboState.TimeLineTickAction.getBuilder()
                            .put(7,DarkCut::summonJudgementCut)
                            .build())
                    .addTickAction(FallHandler::fallDecrease).addHitEffect(StunManager::setStun)::build);
    public static final RegistryObject<ComboState> DarkCutsEX =COMBO_STATES.register("dark_cut_ex",
            ComboState.Builder.newInstance().startAndEnd(1923, 1928).speed(0.4F).priority(50)
                    .next(ComboState.TimeoutNext.buildFromFrame(15, entity -> SlashBlade.prefix("none")))
                    .nextOfTimeout(entity -> Sjap_adder.prefix("all_reuse"))
                    .addTickAction(ComboState.TimeLineTickAction.getBuilder()
                            .put(7,DarkCut::summonJudgementCutEX)
                            .build())
                    .addTickAction(FallHandler::fallDecrease).addHitEffect(StunManager::setStun)::build);


    public static final RegistryObject<ComboState> SAKURA_DRIVE_LEFT = COMBO_STATES.register("sakura_drive_left",
            ComboState.Builder.newInstance().startAndEnd(1816, 1859).speed(6F).priority(50)
                    .next((entity) -> Sjap_adder.prefix("sakura_drive_right"))
                    .nextOfTimeout(entity -> Sjap_adder.prefix("sakura_drive_right"))
                    .clickAction((entityIn) -> AttackManager.doSlash(entityIn, 22.5F, Vec3.ZERO, false, false, Config.sakuraDriveLeftComboRatio))
                    .addTickAction(UserPoseOverrider::resetRot)
                    .addTickAction(ComboState.TimeLineTickAction.getBuilder()
                            .put(1,
                                    (entityIn) ->
                                            mods.flammpfeil.slashblade.slasharts.Drive.doSlash(entityIn, 22.5F, 20,Vec3.ZERO,true,7,0.2f))
                            .build())
                    .addHitEffect(StunManager::setStun)::build);

    public static final RegistryObject<ComboState> SAKURA_DRIVE_RIGHT = COMBO_STATES.register("sakura_drive_right",
            ComboState.Builder.newInstance().startAndEnd(204, 218).speed(1.1F).priority(50)
                    .next((entity) -> SlashBlade.prefix("none"))
                    .nextOfTimeout(entity -> Sjap_adder.prefix("sakura_wave_edge_finish"))
                    .clickAction((entityIn) -> AttackManager.doSlash(entityIn, 180F - 22.5F, Vec3.ZERO, false, true, Config.sakuraDriveRightComboRatio))
                    .addTickAction(UserPoseOverrider::resetRot)
                    .addTickAction(ComboState.TimeLineTickAction.getBuilder()
                            .put(1,
                                    (entityIn) ->
                                            mods.flammpfeil.slashblade.slasharts.Drive.doSlash(entityIn, -22.5F, 20,Vec3.ZERO,true,7,0.2f))
                            .build())                    .addHitEffect((t, a) -> StunManager.setStun(t, 36))::build);




    public static final RegistryObject<ComboState> XrossThunder = COMBO_STATES.register("xross_thunder",
            ComboState.Builder.newInstance().startAndEnd(1816, 1859).speed(6F).priority(50)
                    .next((entity) -> Sjap_adder.prefix("xross_thunder_2"))
                    .nextOfTimeout(entity -> Sjap_adder.prefix("xross_thunder_2"))
                    .clickAction((entityIn) -> AttackManager.doSlash(entityIn, 22.5F, Vec3.ZERO, false, false, Config.xrossThunderComboRatio))
                    .addTickAction(UserPoseOverrider::resetRot)
                    .addTickAction(ComboState.TimeLineTickAction.getBuilder()
                            .put(1,
                                    com.dinzeer.sjapadder.sa.XrossThunder::DoSlash)
                            .build())
                    .addHitEffect(StunManager::setStun)::build);

    public static final RegistryObject<ComboState> XrossThunder_2 = COMBO_STATES.register("xross_thunder_2",
            ComboState.Builder.newInstance().startAndEnd(204, 218).speed(1.1F).priority(50)
                    .next((entity) -> SlashBlade.prefix("none"))
                    .nextOfTimeout(entity -> Sjap_adder.prefix("sakura_wave_edge_finish"))
                    .clickAction((entityIn) -> AttackManager.doSlash(entityIn, 180F - 22.5F, Vec3.ZERO, false, true, Config.xrossThunder2ComboRatio))
                    .addTickAction(UserPoseOverrider::resetRot)
                    .addTickAction(ComboState.TimeLineTickAction.getBuilder()

                            .build())                    .addHitEffect((t, a) -> StunManager.setStun(t, 36))::build);














    public static void register(IEventBus a){
        COMBO_STATES.register(a);
    }
}